package com.silver.weibo.utils;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.stereotype.Component;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

public class MyContextUtil {

    private static final Logger logger = LogManager.getLogger(MyContextUtil.class);

    // 获取会话的request
    public static HttpServletRequest getRequest() {
        ServletRequestAttributes attribute = (ServletRequestAttributes) RequestContextHolder.currentRequestAttributes();

        return attribute.getRequest();
    }

    // 获取会话的response
    public static HttpServletResponse getResponse() {
        ServletRequestAttributes attribute = (ServletRequestAttributes) RequestContextHolder.currentRequestAttributes();

        return attribute.getResponse();
    }

    // 获取 session
    public static HttpSession getSession() {
        HttpServletRequest request = getRequest();

        return request.getSession();
    }
}
